package com.bootcamp.ex1124.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: MyMavenProject
 * @description:
 * @author: Keyu Li
 * @create: 2021-11-24 14:35
 **/


public class CustomInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("username")==null) {
            response.setContentType("application/json");
            response.getWriter().println("{\"username\":\"你好\"}");
            return false;
        }
        return true;
    }
}
